package com.lingchen.utils;

/**
 * Author    lingchen
 * Email     838878458@qq.com
 * Time      2018/2/28
 * Function  字符工具
 */
public class StringUtil {

    /**
     * <p>Checks if a CharSequence is whitespace, empty ("") or null.</p>
     * <p>
     * <pre>
     * StringUtils.isBlank(null)      = true
     * StringUtils.isBlank("")        = true
     * StringUtils.isBlank(" ")       = true
     * StringUtils.isBlank("bob")     = false
     * StringUtils.isBlank("  bob  ") = false
     * </pre>
     *
     * @param cs the CharSequence to check, may be null
     * @return {@code true} if the CharSequence is null, empty or whitespace
     * @since 3.0 Changed signature from isBlank(String) to isBlank(CharSequence)
     */
    public static boolean isBlank(final CharSequence cs) {
        int strLen;
        if (cs == null || (strLen = cs.length()) == 0) {
            return true;
        }
        for (int i = 0; i < strLen; i++) {
            if (Character.isWhitespace(cs.charAt(i)) == false) {
                return false;
            }
        }
        return true;
    }

    /**
     * 获取答案 代码
     *
     * @param answ
     * @return
     */
    public static int getAnsw(String answ) {
        if (StringUtil.isBlank(answ)) return -1;
        if (answ.equals("A")) {
            return 1;
        } else if (answ.equals("B")) {
            return 2;
        } else if (answ.equals("C")) {
            return 3;
        } else {
            return 4;
        }
    }
}
